package com.chenglin.mapdemo.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chenglin.mapdemo.R;
import com.chenglin.mapdemo.bean.LayerBean;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * 多图层 适配器
 */
public class LayerAdapter extends RecyclerView.Adapter<LayerAdapter.MyHolder> {


    private Context context;
    private List<LayerBean> list;
    private LayerAdaterCallBack callBack;

    public LayerAdapter(Context context, List<LayerBean> list, LayerAdaterCallBack callBack) {
        this.context = context;
        this.list = list;
        this.callBack = callBack;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_layer_adapter, parent, false);
        return new MyHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        holder.setIsRecyclable(false);
        holder.tvType.setText(list.get(position).getOut_name());
        holder.rvType.setLayoutManager(new GridLayoutManager(context, 2, GridLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });

        holder.rvType.setAdapter(new LayerInnerAdapter(context, list.get(position).getInner(), new LayerInnerAdapter.InnerLayerCallBack() {
            @Override
            public void onItemClick(LayerBean.InnerBean bean, int innerPosition) {

                callBack.onItemCallBack(bean, position, innerPosition);
            }

        }));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    public class MyHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_type)
        TextView tvType;
        @BindView(R.id.rv_type)
        RecyclerView rvType;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


    public interface LayerAdaterCallBack {
        void onItemCallBack(LayerBean.InnerBean bean, int position, int innerPosition);
    }
}
